define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'form4/index',
        add_url: 'form4/add',
        edit_url: 'form4/edit',
        delete_url: 'form4/delete',
        export_url: 'form4/export',
        modify_url: 'form4/modify',
        touch_index_url: 'form4/touch_index',
        temperature_url: 'form4/temperature_index',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh',
                    [{
                        text: '添加',
                        url: init.add_url,
                        method: 'open',
                        auth: 'add',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-plus ',
                        extend: 'data-width="800px" data-height="630px"',
                    }],
                    'delete'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID', width: 80},
                    {field: 'name', title: '姓名', width: 100},
                    {field: 'sex', selectList:['男','女'], title: '性别', width: 80},
                    {field: 'id_card', title: '身份证号', width: 180},
                    {field: 'living', title: '现居住地址', width: 180},
                    {field: 'domicile', title: '户籍所在地', width: 180},
                    {field: 'employer', title: '工作单位', width: 150},
                    {field: 'mobile', title: '手机号', width: 150},
                    {field: 'community', selectList: getCommunityList, title: '居住地所属社区', width: 150},
                    {field: 'level', search: 'select', width: 120, selectList: {"1":"一密","2":"二密","3":"三密"}, title: '密接等级'},
                    {field: 'create_time', title: '创建时间', width: 160, search: 'range'},
                    {
                        width: 240,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '体温记录',
                                url: init.temperature_url,
                                method: 'open',
                                auth: 'temperature',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                                extra: 'name',
                            }, {
                                text: '接触者',
                                url: init.touch_index_url,
                                method: 'open',
                                auth: 'touch',
                                class: 'layui-btn layui-btn-xs layui-btn-warm',
                                extend: 'data-full="true"',
                                extra: 'name',
                            }, {
                                text: '编辑',
                                url: init.edit_url,
                                method: 'open',
                                auth: 'edit',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                                extend: 'data-width="800px" data-height="630px"',
                                extra: 'name',
                            }, {
                                text: '删除',
                                title: '确定删除？',
                                url: init.delete_url,
                                method: 'request',
                                auth: 'delete',
                                class: 'layui-btn layui-btn-xs layui-btn-danger',
                                extra: 'name',
                            }]
                        ]
                        , fixed: 'right'
                    }

                ]],
            });

            ea.listen();
        },
        temperature_index: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: 'form4/temperature_index?id=' + source_id,
                },
                toolbar: ['refresh',
                    [{
                        text: '添加',
                        url: 'form4/temperature_add?id=' + source_id,
                        method: 'open',
                        auth: 'temperature_add',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-plus ',
                    }]
                ],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID', width: 100},
                    {field: 'form4.name', title: '姓名'},
                    {field: 'id_card', title: '身份证号'},
					{field: 'form4.mobile', title: '手机号'},
                    {field: 'temperature', title: '体温（℃）', templet: function (d) {
                            if (d.temperature > 37.3) {
                                return '<div class="layui-table-cell" style="background-color: red;color: #fff;">' + d.temperature + '</div>';
                            }
                            return '<div class="layui-table-cell">' + d.temperature + '</div>';
                        }},
                    {field: 'create_time', title: '上报时间', search: 'range'},
                ]],
            });

            ea.listen();
        },
        temperature_add: function () {
            ea.listen();
        },
        touch_index: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: 'form4/touch_index?id=' + source_id,
                },
                toolbar: [
                    'refresh',
                    [{
                        text: '添加',
                        url: 'form4/touch_add?source_id=' + source_id,
                        method: 'open',
                        auth: 'add',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-plus ',
                    },
                    {
                        text: '删除',
                        url: 'form4/touch_delete',
                        method: 'request',
                        auth: 'delete',
                        class: 'layui-btn layui-btn-sm layui-btn-danger',
                        icon: 'fa fa-trash-o ',
                    }]
                ],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID', width: 100},
                    {field: 'name', title: '姓名'},
                    {field: 'form4.name', title: '密接上级', search: false},
                    {field: 'sex', search: 'select', selectList: ["男","女"], title: '性别'},
                    {field: 'id_card', title: '身份证号'},
                    // {field: 'living', title: '现居住地址'},
                    {field: 'mobile', title: '手机号'},
                    {field: 'desc', title: '备注', search: false},
                    {field: 'create_time', title: '创建时间', search: 'range'},
                    {
                        width: 180,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '编辑',
                                url: 'form4/touch_edit',
                                method: 'open',
                                auth: 'edit',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                            }, {
                                text: '删除',
                                title: '确定删除？',
                                url: 'form4/touch_delete',
                                method: 'request',
                                auth: 'delete',
                                class: 'layui-btn layui-btn-xs layui-btn-danger',
                            }]
                        ]
                    }
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        touch_add: function () {
            ea.listen();
        },
        touch_edit: function () {
            ea.listen();
        },
    };
    return Controller;
});